//
//  BLAlertController.m
//  UIAlertController
//
//  Created by 宝龙 on 16/5/28.
//  Copyright © 2016年 宝龙. All rights reserved.
//

#import "BLAlertController.h"

@interface BLAlertController ()


@end

@implementation BLAlertController

#pragma mark - AlertStyle
//确定取消其他键
+ (instancetype)blAlertStyleWithAlertStyleForController:(UIViewController *)viewController withTitle:(NSString *)title message:(NSString *)message  determineButtonTitle:(NSString *)determineButtonTitle cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles ActionBlock:(ActionBlock)AtionBlock
{
    return [BLAlertController blAlertForController:viewController withTitle:title message:message AlertControllerStyle:UIAlertControllerStyleAlert  determineButtonTitle:determineButtonTitle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles ActionBlock:AtionBlock];
}
//确定取消键
+ (instancetype)blAlertStyleWithAlertStyleForController:(UIViewController *)viewController withTitle:(NSString *)title message:(NSString *)message  determineButtonTitle:(NSString *)determineButtonTitle cancelButtonTitle:(NSString *)cancelButtonTitle  ActionBlock:(ActionBlock)AtionBlock
{
    return [BLAlertController blAlertForController:viewController withTitle:title message:message AlertControllerStyle:UIAlertControllerStyleAlert  determineButtonTitle:determineButtonTitle cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil ActionBlock:AtionBlock];
}

//确定键
+ (instancetype)blAlertStyleWithAlertStyleForController:(UIViewController *)viewController withTitle:(NSString *)title message:(NSString *)message  determineButtonTitle:(NSString *)determineButtonTitle  ActionBlock:(ActionBlock)AtionBlock
{
    return [BLAlertController blAlertForController:viewController withTitle:title message:message AlertControllerStyle:UIAlertControllerStyleAlert  determineButtonTitle:determineButtonTitle cancelButtonTitle:nil otherButtonTitles:nil ActionBlock:AtionBlock];
}



#pragma mark - SheetStyle
//确定取消其他键
+ (instancetype)blAlertStyleWithSheetStyleForController:(UIViewController *)viewController withTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle determineButtonTitle:(NSString *)determineButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles ActionBlock:(ActionBlock)AtionBlock
{
    return [BLAlertController blAlertForController:viewController withTitle:title message:message AlertControllerStyle:UIAlertControllerStyleActionSheet  determineButtonTitle:determineButtonTitle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles ActionBlock:AtionBlock];
}


//确定取消键
+ (instancetype)blAlertStyleWithSheetStyleForController:(UIViewController *)viewController withTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle determineButtonTitle:(NSString *)determineButtonTitle ActionBlock:(ActionBlock)AtionBlock
{
    return [BLAlertController blAlertForController:viewController withTitle:title message:message AlertControllerStyle:UIAlertControllerStyleActionSheet  determineButtonTitle:determineButtonTitle cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil ActionBlock:AtionBlock];
}







+ (instancetype)blAlertForController:(UIViewController *)viewController
                             withTitle:(NSString *)title
                           message:(NSString *)message
                          AlertControllerStyle:(UIAlertControllerStyle) alertControllerStyle
              determineButtonTitle:(NSString *)determineButtonTitle
                   cancelButtonTitle:(NSString *)cancelButtonTitle
                      otherButtonTitles:(NSArray *)otherButtonTitles
                 ActionBlock:(ActionBlock)AtionBlock {

    BLAlertController *alert = [BLAlertController alertControllerWithTitle:title message:message preferredStyle:alertControllerStyle];
    
    //确定键
    if (determineButtonTitle) {
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:determineButtonTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            if (AtionBlock) {
                AtionBlock(viewController, action, determineButtonTitle);
            }
            
        }];
        [alert addAction:alertAction];
    }
    
    //取消键
    if (cancelButtonTitle) {
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            if (AtionBlock) {
                 AtionBlock(viewController, action, cancelButtonTitle);
            }
            
        }];
        [alert addAction:alertAction];
    }
    
   
    //其他键
    for (int i = 0; i < otherButtonTitles.count; i++) {
        
        NSString *othersTitle = otherButtonTitles[i];
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:othersTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (AtionBlock) {
                AtionBlock(viewController, action, othersTitle);
            }
        }];
        
        [alert addAction:alertAction];
    }
    
    
    [viewController presentViewController:alert animated:YES completion:nil];
    
    return alert;
}







@end
